<?php
/**
 *  用户操作 冻结，解冻，提醒发货
 *	@name		商品拍卖
 *	@author		Jeffery
 *	@qq			1017756891
 *	@email		1017756891@qq.com
 *	@website	http://www.iweitao.net
**/

require_once "core.php";

$act = $core->_get("act");
$acts = array('freeze','unfreeze','remind_checkout');
if(!in_array($act,$acts)) {
	showmessage("参数错误，请返回");
}
if($act == 'freeze') {	//冻结商品
	$tid = $core->_get("tid");
	if($admingroup != $_G['groupid']) {
		showmessage("对不起，您无权进行该操作");
	}
	DB::update('paipai_goods',array('freeze'=>1),"tid = $tid");
	showmessage("订单冻结成功",'forum.php?mod=viewthread&tid='.$tid);
} else if($act == 'unfreeze') {	//解除冻结
	$tid = $core->_get("tid");
	if($admingroup != $_G['groupid']) {
		showmessage("对不起，您无权进行该操作");
	}
	DB::update('paipai_goods',array('freeze'=>0),"tid = $tid");
	showmessage("订单解冻成功",'forum.php?mod=viewthread&tid='.$tid);
} else if($act == 'remind_checkout'){	//提醒卖家结算
	require_once "paipai.class.php";
	$globalclass = new threadplugin_iweitao_paipai();
	$tid = $core->_get("tid");
	$info = $globalclass->getgoodsdetail_by_tid($tid);
	$gid = $info['gid'];
	$query = DB::query("SELECT * FROM `".DB::table("paipai_buy")."` WHERE `tid` = '$tid' and status=1 order by price desc limit 1");
	// 成交订单
	$buy = db_get_one($query);
	// 检测提醒状态
	check_remind($buy['remind'],$tid);

	// var_dump($info);
	
	// 更新成交订单
	DB::update('paipai_buy',array('remind'=>1),"tid = $tid and gid = $gid and status=1 and uid=".$buy['uid']);

	notification_add($info['uid'],'post',"您参与竞拍的艺术品 <a target='_blank' href='forum.php?mod=viewthread&tid=$tid'>".$info['title']."</a> 已经竞拍结束，成交金额 ".$info['price'].";  请您尽快结算",array(),$system = 0);
	
	showmessage("提醒卖家结算成功，请您耐心等待",'forum.php?mod=viewthread&tid='.$tid);

}

/**
 * [check_remind 检测提醒状态]
 * @param  [type] $r [description]
 * @return [type]    [description]
 */
function check_remind($r,$tid){
	$msg = '';
	switch ($r) {
		case '1':
			$msg = "已经提醒卖家结算，请勿重复提醒，交易成交3天后将移交管理员处理，请您耐心等待";
			break;
		case '2':
			$msg = "已经提醒卖家发货，请勿重复提醒，交易成交3天后将移交管理员处理，请您耐心等待";
			break;
		case '3':
			$msg = "已经提交管理员处理，请勿重复提醒，请您耐心等待";
			
			break;
		default:
			break;
	}
	showmessage($msg,'forum.php?mod=viewthread&tid='.$tid);
}


?>